home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / insight / plugins / myvis.pro < prev   
Text File  |  1997-07-08  |  15KB  |  428 lines

  1. ; $Id: myvis.pro,v 1.8 1997/04/23 17:11:13 rob Exp $
  2. ;
  3. ; Copyright (c) 1997, Research Systems, Inc.  All rights reserved.
  4. ;   Unauthorized reproduction prohibited.
  5. ;+
  6. ; FILE:
  7. ;       myvis.pro
  8. ;
  9. ; PURPOSE:
  10. ;       This file contains an example Analysis PlugIn that visualizes data.
  11. ;
  12. ; CONTENTS:
  13. ;       GENERAL ROUTINES
  14. ;           pro SensitizeMyVis          - set widget sensitivity
  15. ;           pro HandleEventsMyVis       - handle dialog box events
  16. ;
  17. ;       CALLBACK ROUTINES
  18. ;           fun ApplyMyVis              - Apply/OK entry point
  19. ;           fun PromptUserMyVis         - main entry point (creates dialog)
  20. ;
  21. ;       REGISTRATION FUNCTION
  22. ;           fun MyVis                   - registers the PlugIn
  23. ;
  24. ;-
  25.  
  26. ; *****************************************************************************
  27. ;       GENERAL ROUTINES
  28. ; *****************************************************************************
  29.  
  30. ; -----------------------------------------------------------------------------
  31. ;
  32. ;   Purpose:  Set widget sensitivity.
  33. ;
  34. pro SensitizeMyVis
  35.  
  36.     ;  Widget state information.
  37.     ;
  38.     common MyVisCommon, psState
  39.  
  40.     ;  Set sensitivity and value shown for visualization insert.
  41.     ;
  42.     visIndex = (*psState).visIndex
  43.     visType = (*psState).visTypes[visIndex]
  44.     sensitive = (visType eq 'plot')
  45.     WIDGET_CONTROL, (*psState).wInsertBgroup, SENSITIVE=sensitive
  46.     if (sensitive) then $
  47.         WIDGET_CONTROL, (*psState).wInsertBgroup, $
  48.             SET_VALUE=((*psState).insert) $
  49.     else $
  50.         WIDGET_CONTROL, (*psState).wInsertBgroup, SET_VALUE=0
  51.  
  52. end                 ; SensitizeMyVis
  53.  
  54. ; -----------------------------------------------------------------------------
  55. ;
  56. ;   Purpose:  Handle dialog events.
  57. ;
  58. pro HandleEventsMyVis, sEvent
  59.  
  60.     ;  Widget state information.
  61.     ;
  62.     common MyVisCommon, psState
  63.     wGroup = (*psState).wMainBase
  64.  
  65.     ;  Catch errors.
  66.     ;
  67.     CATCH, error
  68.     if (error ne 0) then begin
  69.         CATCH, /CANCEL
  70.         void = DIALOG_MESSAGE(!ERR_STRING, DIALOG_PARENT=wGroup)
  71.         RETURN
  72.     endif
  73.  
  74.     ; ========================
  75.     ;     PROCESS EVENTS
  76.     ; ========================
  77.  
  78.     case (sEvent.id) of
  79.  
  80.         ; --------------------------------------
  81.         ;     Input text
  82.         ; --------------------------------------
  83.         (*psState).wInput1Text:     ; (nothing to do now)
  84.         (*psState).wInput2Text:     ; (nothing to do now)
  85.         (*psState).wInput3Text:     ; (nothing to do now)
  86.  
  87.         ; --------------------------------------
  88.         ;     Input browse buttons
  89.         ; --------------------------------------
  90.  
  91.         ;  Let user browser for a data name.
  92.         ;  If user selected an item, set data name in text widget.
  93.         ;
  94.         (*psState).wInput1BrowseButton: begin
  95.             title = 'Select a data item.'
  96.             void = INSGET( $
  97.                 NAME=name, $                ; returned name of data selected
  98.                 /EXCLUSIVE, $               ; only one selection
  99.                 TITLE=title, $              ; title of browser
  100.                 COUNT=count, $              ; returned count of items selected
  101.                 GROUP=wGroup, $             ; widget group leader
  102.                 _EXTRA=(*psState).extra)    ; extra information
  103.             if (count eq 1) then $
  104.                 WIDGET_CONTROL, (*psState).wInput1Text, SET_VALUE=name
  105.         end
  106.  
  107.         (*psState).wInput2BrowseButton: begin
  108.             title = 'Select a data item.'
  109.             void = INSGET( $
  110.                 NAME=name, $                ; returned name of data selected
  111.                 /EXCLUSIVE, $               ; only one selection
  112.                 TITLE=title, $              ; title of browser
  113.                 COUNT=count, $              ; returned count of items selected
  114.                 GROUP=wGroup, $             ; widget group leader
  115.                 _EXTRA=(*psState).extra)    ; extra information
  116.             if (count eq 1) then $
  117.                 WIDGET_CONTROL, (*psState).wInput2Text, SET_VALUE=name
  118.         end
  119.  
  120.         (*psState).wInput3BrowseButton: begin
  121.             title = 'Select a data item.'
  122.             void = INSGET( $
  123.                 NAME=name, $                ; returned name of data selected
  124.                 /EXCLUSIVE, $               ; only one selection
  125.                 TITLE=title, $              ; title of browser
  126.                 COUNT=count, $              ; returned count of items selected
  127.                 GROUP=wGroup, $             ; widget group leader
  128.                 _EXTRA=(*psState).extra)    ; extra information
  129.             if (count eq 1) then $
  130.                 WIDGET_CONTROL, (*psState).wInput3Text, SET_VALUE=name
  131.         end
  132.  
  133.         ; --------------------------------------
  134.         ;     Vis droplist
  135.         ; --------------------------------------
  136.         (*psState).wVisDroplist: begin
  137.  
  138.             ;  Get the visualization index.
  139.             ;
  140.             index = WIDGET_INFO((*psState).wVisDroplist, /DROPLIST_SELECT)
  141.             (*psState).visIndex = index
  142.  
  143.             ;  Set widget sensitivity based on visualization selected.
  144.             ;
  145.             SensitizeMyVis
  146.         end
  147.  
  148.         ; --------------------------------------
  149.         ;     Insert bgroup
  150.         ; --------------------------------------
  151.         (*psState).wInsertBgroup: begin
  152.  
  153.             WIDGET_CONTROL, (*psState).wInsertBgroup, GET_VALUE=value
  154.             (*psState).insert = value[0]
  155.  
  156.         end
  157.  
  158.         ; --------------------------------------
  159.         ;     OK/Apply/Cancel buttons
  160.         ; --------------------------------------
  161.         (*psState).wOKApplyCancelButtons: begin
  162.  
  163.             ;  Destroy dialog on successful OK selection, or if user canceled.
  164.             ;
  165.             if ((sEvent.type eq 'OK') or $
  166.                 (sEvent.type eq 'Cancel')) then $
  167.                 WIDGET_CONTROL, (*psState).wMainBase, /DESTROY
  168.         end
  169.  
  170.         ; --------------------------------------
  171.         ;     other events
  172.         ; --------------------------------------
  173.         else:   ; (do nothing)
  174.  
  175.     endcase
  176.  
  177. end                 ; HandleEventsMyVis
  178.  
  179. ; *****************************************************************************
  180. ;       CALLBACK ROUTINES
  181. ; *****************************************************************************
  182.  
  183. ; -----------------------------------------------------------------------------
  184. ;
  185. ;   Purpose:  Get data and visualize it.
  186. ;             Fuction returns 1B on success, else 0B.
  187. ;
  188. function ApplyMyVis, $
  189.     CIDs=CIDs, $            ; OUT: command ID list from INSPUT/INSVIS calls
  190.     DATA_NAME=dataName, $   ; IN: name of data selected in visualization window
  191.     _EXTRA=extra            ; IN: information to pass to commands
  192.  
  193.     ;  Widget state information.
  194.     ;
  195.     common MyVisCommon, psState
  196.     wGroup = (*psState).wMainBase
  197.  
  198.     ; ---------------------------------------------------------
  199.     ;  Catch errors.
  200.     ; ---------------------------------------------------------
  201.  
  202.     CATCH, error
  203.     if (error ne 0) then begin
  204.         CATCH, /CANCEL
  205.         void = DIALOG_MESSAGE(!ERR_STRING, DIALOG_PARENT=wGroup)
  206.         RETURN, 0B
  207.     endif
  208.  
  209.     ; ---------------------------------------------------------
  210.     ;  Get inputs.
  211.     ; ---------------------------------------------------------
  212.  
  213.     ;  Get visualization type.
  214.     ;
  215.     visIndex = (*psState).visIndex
  216.     visType = (*psState).visTypes[visIndex]
  217.  
  218.     ;  Get all input data names.
  219.     ;
  220.     WIDGET_CONTROL, (*psState).wInput1Text, GET_VALUE=value
  221.     input1Name = value[0]
  222.     WIDGET_CONTROL, (*psState).wInput2Text, GET_VALUE=value
  223.     input2Name = value[0]
  224.     WIDGET_CONTROL, (*psState).wInput3Text, GET_VALUE=value
  225.     input3Name = value[0]
  226.  
  227.     ;  (Let INSVIS do error checking...
  228.     ;   only problem is that the messages won't use correct field names.)
  229.  
  230.     ; ---------------------------------------------------------
  231.     ;  Visualize data.
  232.     ; ---------------------------------------------------------
  233.  
  234.     ;  Set the visualization mode.
  235.     ;
  236.     mode = 'new'
  237.     if ((visType eq 'plot') and ((*psState).insert)) then $
  238.         mode = 'insert'
  239.  
  240.     ;  Visualize the data.
  241.     ;
  242.     ;  (Notice you can pass an empty string or undefined value as
  243.     ;   the third, or the second and third arguments to INSVIS.)
  244.     ;
  245.     INSVIS, $
  246.         input1Name, $                           ; name of data item
  247.         input2Name, $                           ; name of 2nd data item
  248.         input3Name, $                           ; name of 3rd data item
  249.         TYPE                = visType, $        ; visualization type
  250.         MODE                = mode, $           ; insert | new | overlay
  251.         CIDs                = CIDs, $           ; command ID list
  252.         GROUP               = wGroup, $         ; widget group leader
  253.         _EXTRA              = extra             ; extra information
  254.  
  255.     ; ---------------------------------------------------------
  256.     ;  Successful return.
  257.     ; ---------------------------------------------------------
  258.  
  259.     RETURN, 1B
  260.  
  261. end                 ; ApplyMyVis
  262.  
  263. ; -----------------------------------------------------------------------------
  264. ;
  265. ;   Purpose:  Main entry point for the PlugIn.
  266. ;
  267. pro PromptUserMyVis, $
  268.     GROUP=wGroup, $         ; IN: group leader widget ID
  269.     DATA_NAME=dataName, $   ; IN: name of data selected in visualization window
  270.     _EXTRA=extra            ; IN: various information
  271.  
  272.     ;  Widget state information.
  273.     ;
  274.     common MyVisCommon, psState
  275.  
  276.     ;  Set visualization types.
  277.     ;
  278.     visTypes = [ $
  279.         'plot', $
  280.         'scatter', $
  281.         'histogram', $
  282.         'polar', $
  283.         'contour', $
  284.         'image', $
  285.         'surface' $
  286.         ]
  287.     visTypesTitles = [ $
  288.         'plot      (Y [, X])'     , $
  289.         'scatter   (Y [, X])'     , $
  290.         'histogram (Y [, X])'     , $
  291.         'polar     (R, T)'        , $
  292.         'contour   (Z [, X, Y])'  , $
  293.         'image     (I)'           , $
  294.         'surface   (Z [, X, Y])'    $
  295.         ]
  296.     visIndex = 0
  297.  
  298.     ;  Create modal main base (non-sizable).
  299.     ;
  300.     title = 'Analysis PlugIn Example - My Vis'
  301.     wMainBase = WIDGET_BASE(TITLE=title, GROUP_LEADER=wGroup, $
  302.         /COLUMN, /MODAL, /TLB_FRAME_ATTR)
  303.  
  304.     value = [ $
  305.         'Specify data, choose how to visualize, ' + $
  306.         'then hit Apply or OK.' $
  307.         ]
  308.     for i = 0, N_ELEMENTS(value)-1 do $
  309.         void = WIDGET_LABEL(wMainBase, VALUE=value[i])
  310.  
  311.     ; ------------------------------------------
  312.     ;  Create INPUTS widgets.
  313.     ; ------------------------------------------
  314.  
  315.     wInputsBase = WIDGET_BASE(wMainBase, /COLUMN, /FRAME)
  316.     void = WIDGET_LABEL(wInputsBase, VALUE='INPUTS')
  317.  
  318.     xs = 40
  319.     wInput1DataBase = WIDGET_BASE(wInputsBase, /ROW)
  320.     void = WIDGET_LABEL(wInput1DataBase, VALUE='Input1: ')
  321.     wInput1Text = WIDGET_TEXT(wInput1DataBase, VALUE=dataName, /EDITABLE, $
  322.         XSIZE=xs)
  323.     wInput1BrowseButton = WIDGET_BUTTON(wInput1DataBase, VALUE=' Browse... ')
  324.  
  325.     wInput2DataBase = WIDGET_BASE(wInputsBase, /ROW)
  326.     void = WIDGET_LABEL(wInput2DataBase, VALUE='Input2: ')
  327.     wInput2Text = WIDGET_TEXT(wInput2DataBase, VALUE='', /EDITABLE, XSIZE=xs)
  328.     wInput2BrowseButton = WIDGET_BUTTON(wInput2DataBase, VALUE=' Browse... ')
  329.  
  330.     wInput3DataBase = WIDGET_BASE(wInputsBase, /ROW)
  331.     void = WIDGET_LABEL(wInput3DataBase, VALUE='Input3: ')
  332.     wInput3Text = WIDGET_TEXT(wInput3DataBase, VALUE='', /EDITABLE, XSIZE=xs)
  333.     wInput3BrowseButton = WIDGET_BUTTON(wInput3DataBase, VALUE=' Browse... ')
  334.  
  335.     ; ------------------------------------------
  336.     ;  Create OUTPUTS widgets.
  337.     ; ------------------------------------------
  338.  
  339.     wOutputsBase = WIDGET_BASE(wMainBase, /COLUMN, /FRAME)
  340.     value = '                 OUTPUTS'
  341.     void = WIDGET_LABEL(wOutputsBase, VALUE=value)
  342.  
  343.     ;  Create visualization droplist.
  344.     ;
  345.     padding = '     '
  346.     wOutputsRowBase = WIDGET_BASE(wOutputsBase, /ROW)
  347.     void = WIDGET_LABEL(wOutputsRowBase, VALUE=padding)
  348.     wVisDroplist = WIDGET_DROPLIST(wOutputsRowBase, $
  349.         VALUE=visTypesTitles, TITLE='Visualization Type: ')
  350.     WIDGET_CONTROL, wVisDroplist, SET_DROPLIST_SELECT=visIndex
  351.  
  352.     ;  Create insert checkbox.
  353.     ;
  354.     insert = 0
  355.     void = WIDGET_LABEL(wOutputsRowBase, VALUE=padding)
  356.     wInsertBgroup = CW_BGROUP(wOutputsRowBase, ['Insert'], $
  357.         /NONEXCLUSIVE, SET_VALUE=insert)
  358.  
  359.     ; ------------------------------------------
  360.  
  361.     ;  Create OK/Apply/Cancel buttons using special compound widget.
  362.     ;  (Must pass in main modal base, used to set default and cancel buttons.)
  363.     ;
  364.     wOKApplyCancelButtons = CW_INSAPPLY(wMainBase, _EXTRA=extra)
  365.  
  366.     ;  Create dialog state information.
  367.     ;
  368.     sState = { $
  369.         extra: extra, $
  370.         visTypes: visTypes, $
  371.         visIndex: visIndex, $
  372.         wMainBase: wMainBase, $
  373.         wInput1Text: wInput1Text, wInput1BrowseButton: wInput1BrowseButton, $
  374.         wInput2Text: wInput2Text, wInput2BrowseButton: wInput2BrowseButton, $
  375.         wInput3Text: wInput3Text, wInput3BrowseButton: wInput3BrowseButton, $
  376.         wVisDroplist: wVisDroplist, $
  377.         wInsertBgroup: wInsertBgroup, insert: insert, $
  378.         wOKApplyCancelButtons: wOKApplyCancelButtons $
  379.         }
  380.  
  381.     ;  Store the state in a heap variable.
  382.     ;
  383.     psState = PTR_NEW(sState, /NO_COPY)
  384.  
  385.     ;  Set widget (insert checkbox) sensitivity.
  386.     ;
  387.     SensitizeMyVis
  388.  
  389.     ;  Realize the dialog box.
  390.     ;
  391.     WIDGET_CONTROL, wMainBase, /REALIZE
  392.  
  393.     ;  Start event loop.
  394.     ;
  395.     XMANAGER, 'PromptUserMyVis', wMainBase, EVENT_HANDLER='HandleEventsMyVis'
  396.  
  397.     ;  Remove widget state info.
  398.     ;
  399.     PTR_FREE, psState
  400.  
  401. end                 ; PromptUserMyVis
  402.  
  403. ; *****************************************************************************
  404. ;       REGISTRATION FUNCTION
  405. ; *****************************************************************************
  406.  
  407. ; -----------------------------------------------------------------------------
  408. ;
  409. ;   Purpose:  Register the Analysis PlugIn.
  410. ;
  411. function MyVis
  412.  
  413.     ;  Return the Analysis PlugIn Registration Structure.
  414.     ;
  415.     RETURN, { $
  416.         type:       'Analysis_PlugIn', $            ; PlugIn type
  417.         title:      'My Vis...', $                  ; PlugIn title
  418.         purpose:    'Do example visualizations.', $ ; PlugIn purpose
  419.         main_proc:  'PromptUserMyVis', $            ; main callback
  420.         apply_func: 'ApplyMyVis', $                 ; apply callback
  421.         version:    '5.0', $                        ; IDL version
  422.         revision:   '1.0' $                         ; PlugIn version
  423.         }
  424.  
  425. end                 ; MyVis
  426.  
  427. ; -----------------------------------------------------------------------------
  428.